<?php
//Define Sub Menu Items++++++++++++++++++
$subMenuItems = array("MANAGE UNDERWRITERS","MANAGE AIR TIMES","MANAGE GRID");


//############################
//BEGIN FIGURE OUT CRUMB TRAIL
//############################
$crumb = $subMenuItems[$subMenu];
//figure out subCrumb
if($subMenu == '2'){
	//INFO FOR AIR TIME DROP DOWN MENU

	if($action == 'planner' || !$action){
    	$action = 'planner';
		$subCrumb = "Weekly Planner";
	}else if($action == 'view'){
		$subCrumb = "Live Grid";
	}else if($action == 'modifyGrid'){
		$subCrumb = "Update Grid Items";
	}else if($action == 'enter'){
		$subCrumb = "Enter New Grid Items";
	}else if($action == 'verify'){
		$subCrumb = "Verify New Entries";
	}
}else if($subMenu == '1'){
	//INFO FOR AIR TIME DROP DOWN MENU

	if($action == 'list' || !$action){
        $action = 'list';
		$subCrumb = "List Air Times";
	}else if($action == 'enter' || isset($_GET['fromPlannerID'])){
		$subCrumb = "Enter New Air Time";
		$action = 'enter';
	}else if($action == 'update'){
		$subCrumb = "Update Air Time";
	}
}else if($subMenu == '0'){
	//INFO FOR UNDERWRITERS DROP DOWN MENU

	if($action == 'list' || !$action){
	    $action = 'list';
		$subCrumb = "List Underwriters";
	}else if($action == 'modify'){
		$subCrumb = "Modify Underwriter";
	}else if($action == 'enter'){
		$subCrumb = "Enter Underwriter";
	}else if($action == 'search'){
		$subCrumb = "Search Underwriters";
	}
}
//############################
//END FIGURE OUT CRUMB TRAIL
//############################



//=====================================
//BEGIN HEADER DECO====================
//=====================================
    echo"<table width=\"100%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
  <tr>
    <td style=\"width:25px; background-image:url(images/subHeaderGradient.gif);background-position:left top;background-repeat: repeat-y;\" ></td>
    <td style=\"background-image:url(images/sysAdmin.gif);background-position:left center;background-repeat: no-repeat;\"  class=\"subHeader\" ><U>$pageTitle</U> :: $crumb :: $subCrumb</td>
    <td align=\"right\" valign=\"middle\" style=\"padding-right:20px; background-color:#000000; background-image:url(images/subHeaderCorner.gif); background-position:right top;background-repeat:no-repeat;\"></td>
  </tr></TABLE>";
//=====================================
//END HEADER DECO======================
//=====================================





//==========================================================================================
//BEGIN CODE FOR MANAGE UNDERWRITERS========================================================
//==========================================================================================

if($subMenu == '0'){

$tabWidths = array();
  $tabWidths[0]['left'] = '0';
  $tabWidths[0]['text'] = 'List Underwriters';
  $tabWidths[0]['action'] = 'list';

  $tabWidths[1]['left'] = '-25';
  $tabWidths[1]['text'] = 'Enter Underwriter';
  $tabWidths[1]['action'] = 'enter';

  $tabWidths[2]['left'] = '-45';
  $tabWidths[2]['text'] = 'Modify Underwriter';
  $tabWidths[2]['action'] = 'modify';

  $tabWidths[3]['left'] = '-70';
  $tabWidths[3]['text'] = 'Search Underwriters';
  $tabWidths[3]['action'] = 'search';



  //ADMIN NAVIGATION  - links get there styles from CSS: #admintopnav #a3
echo"<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
	<TR>
		<TD valign=\"bottom\"><ul id=\"admintopnav\">";

		for ($i = 0; $i < count($tabWidths); $i++) {
			if($action == $tabWidths[$i]['action']){
				echo "<li ><DIV style=\"left:" .$tabWidths[$i]['left']."px;\" class=\"hereUnderwriters\">" .$tabWidths[$i]['text']. "</DIV></li>";
			}else{
				echo"<li ><a id=\"a".($i+3)."\" href=\"index.php?ID=0&subMenu=0&action=".$tabWidths[$i]['action']."\" >" .$tabWidths[$i]['text']. "</a></li>";
			}
		}

			echo"</ul>
		</TD>
	</TR>
	<TR><TD><DIV class=\"adminsubnav3\"></DIV></TD></TR>
	</TABLE>";
 //END ADMIN NAVIGATION





		//+++++++++++++++++++++++
		//BEGIN CODE FOR LISTING UW's
		//+++++++++++++++++++++++
if($action=='list'  || !$action){
		//Javascript function to confirm delete
		echo("<script language=\"JavaScript\" type=\"text/javascript\">
		function confirmDelete() {
		var cMsg = \"\";
			for (var q=0; q < document.form.elements.length; q++) {
				 // get each element of form form
				 var e = document.form.elements[q];
				 if( e.name.indexOf(\"radioGroup\") == -1 ){
				// not a radioGroup element
				continue;
  				}
				 // determine whether delete radio button is checked
				if( e.value.indexOf(\"delete\") == -1 ){
				continue;
				}

				if(e.checked == true){
				var i = e.name.replace(/radioGroup/,\"\");
				var h = document.form.elements[\"deleteID\" + i];
				cMsg += \"\\t\" + h.value + \"\\n\";
  				}
			//ends Loop
			}

		if( cMsg != \"\" ){

		  // we have some deletes to confirm
		  cMsg = \"You are about to delete the following underwriters:\\n\\n\" + cMsg + \"\\nContinue?\";
		  if(confirm(cMsg)){
		 document.form.submit();
		  }else{
		 return false;
		  }


		}else {
		document.form.submit();
		}

		//ends function
		}
		</script>");




		//javascript to submit form on pressing enter
		echo"<script language=\"JavaScript\">
		<!--
		function submitForm(event,formName){
			if(event.keyCode==13 || (event && event.which == 13)){
				confirmDelete();
			}
		}
		//-->
		</script> ";


		//Start "Manage UW Drop Down Jump List
		echo"<form style='padding:0; margin:0;' name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" onKeyPress=\"submitForm(event,'form');\">";
		echo"<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\">";
		echo("<TR><TD valign=\"top\" align=\"center\">");

		if(isset($_SESSION['result'])){//list out results from search form
			$result = $_SESSION['result'];
			unset($_SESSION['result']);
		}else{
			$Query = "SELECT * FROM $underwriter_Table ORDER BY name asc";
			$result = $db->getAll($Query, DB_FETCHMODE_ASSOC);
			if (DB::isError($result)) {
			die ($result->getMessage());
			}
		}


		//$Query = mysql_query("SELECT * FROM underwriters ORDER BY name asc", $link);
		echo("<TABLE width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">");
		echo("<TR class=\"blockHeader\"> <TD></TD> <TD >Underwriter</TD> <TD>System ID</TD> <TD width=\"1%\">Action</TD> </TR>");

		$i = 0;
		$ii =1;
		while ($i < count($result)) {
    	$ID = $result[$i][ID];
		$UW_Name = stripslashes($result[$i]['name']);
		$Abbreviation = stripslashes($result[$i]['abbreviation']);
		echo("<input name=\"deleteID$i\" type=\"hidden\" value=\"$UW_Name\">");
		if($i & 1){
		echo("<TR onmouseover=\"setPointer(this, $i, 'over', '#CCCCCC', '#CCFFCC', '#FFCC99');\" onmouseout=\"setPointer(this, $i, 'out', '#CCCCCC', '#CCFFCC', '#FFCC99');\" onmousedown=\"setPointer(this, $i, 'click', '#CCCCCC', '#CCFFCC', '#FFCC99');\"> <TD bgcolor=\"#CCCCCC\" class=\"numbers\">$ii)</TD> <TD bgcolor=\"#CCCCCC\" class=\"blockContent1\">$UW_Name</TD> <TD bgcolor=\"#CCCCCC\" class=\"blockContent1\">$Abbreviation</TD> <TD bgcolor=\"#CCCCCC\" nowrap class=\"formElementTextLeft\">update<INPUT name=\"radioGroup$i\" type=\"radio\" value=\"update:$ID\"> | delete<INPUT name=\"radioGroup$i\" type=\"radio\" value=\"delete:$ID\"></TD></TR>\n");
		}else{
		echo("<TR onmouseover=\"setPointer(this, $i, 'over', '#FFFFFF', '#CCFFCC', '#FFCC99');\" onmouseout=\"setPointer(this, $i, 'out', '#FFFFFF', '#CCFFCC', '#FFCC99');\" onmousedown=\"setPointer(this, $i, 'click', '#FFFFFF', '#CCFFCC', '#FFCC99');\"> <TD bgcolor=\"#FFFFFF\" class=\"numbers\">$ii)</TD> <TD bgcolor=\"#FFFFFF\" class=\"blockContent1\">$UW_Name</TD> <TD bgcolor=\"#FFFFFF\" class=\"blockContent1\">$Abbreviation</TD> <TD bgcolor=\"#FFFFFF\" nowrap class=\"formElementTextLeft\">update<INPUT name=\"radioGroup$i\" type=\"radio\" value=\"update:$ID\"> | delete<INPUT name=\"radioGroup$i\" type=\"radio\" value=\"delete:$ID\"></TD></TR>\n");
		}
		++$i;
		++$ii;
		}

		echo("<INPUT name=\"highnumber\" type=\"hidden\" value=\"$i\"></TABLE>");
		echo("</TD></TR>");
		echo("<TR><TD valign=\"middle\" align=\"center\" bgcolor=\"#666666\"><INPUT name=\"action\" type=\"hidden\" value=\"list\"><INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" onClick=\"confirmDelete()\"> &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"reset\" class=\"inputButton\" value=\"Reset\"></TD></TR>");

		echo("</TABLE></FORM>");

}
		//+++++++++++++++++++++++
		//END CODE FOR LISTING UW's
		//+++++++++++++++++++++++




		//+++++++++++++++++++++++
		//BEGIN CODE FOR ENTERING NEW UW's
		//+++++++++++++++++++++++
if($action=='enter'){

		//javascript to submit form on pressing enter
		echo"<script language=\"JavaScript\">
		<!--
		function submitForm(event,formName){
			if(event.keyCode==13 || (event && event.which == 13)){
				formCheck();
			}
		}
		//-->
		</script> ";

		echo"<form style='padding:0; margin:0;' name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" onKeyPress=\"submitForm(event,'form');\">";
		echo"<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\">";

		echo("<script type=\"text/javascript\" language=\"JavaScript\">
		function formCheck(){

		if(document.form.name.value==\"\"){
		document.form.name.focus();
		alert (\"Please complete all Fields!\");
		}else if(document.form.abbreviation.value==\"\"){
		document.form.abbreviation.focus();
		alert (\"Please complete all Fields!\");
		}else{
		document.form.submit();
		}
			}
		// -->
		</script>");


echo"<!--BEGIN Row for Entering new underwriters-->
<TR><TD>

  <table width=\"100%\"  border=\"0\" cellpadding=\"4\"><TR><TD>
  <table border=\"1\" width=\"100%\"  cellpadding=\"0\" cellspacing=\"0\"><TR><TD>

  	<table border=\"0\" width=\"100%\"  cellpadding=\"0\" cellspacing=\"0\">
	    <form action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" name=\"PrintOptions\">

		<TR>
			<TD class=\"blockHeader\">
			Enter A New Underwriter:
			</TD>
		</TR>

		<TR>
			<TD class=\"blockDescription\">
			Use a three letter abreviation to identify the new underwriter in the grid.
			</TD>
		</TR>

		<TR>
			<TD>
							<table border=\"0\" width=\"100%\"  cellpadding=\"4\" cellspacing=\"0\">
				<TR class=\"formElementText\" bgcolor=\"FFFFFF\">
					<TD>";



							echo "Full Name: <INPUT name=\"name\" type=\"text\" size=\"30\">";


					echo"</TD><TD>";

							echo "System ID: <INPUT name=\"abbreviation\" type=\"text\" size=\"30\">";

					echo"</TD>
				</TR>
	</TABLE>
  			</TD>
		</TR>

		<!--SUBMIT BUTTON-->
  		<TR>
			<TD bgcolor=\"#CCCCCC\" align=\"center\" style=\"padding-top:5px; padding-bottom:5px; \">
            <INPUT name=\"action\" type=\"hidden\" value=\"enter\"><INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" onClick=\"formCheck()\"> &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"reset\" class=\"inputButton\" value=\"Reset\">			</TD>
		</TR>
		<!--END SUBMIT BUTTON-->
		  </FORM>

  </TABLE>
  </TD></TR></TABLE>
  </TD></TR></TABLE>

  </TD></TR>
  <!--END Row for Entering new underwriters-->";
echo("</TABLE></FORM>");


}
		//+++++++++++++++++++++++
		//END CODE FOR ENTERING NEW UW's
		//+++++++++++++++++++++++




		//+++++++++++++++++++++++
		//BEGIN CODE FOR MODIFYING UW's
		//+++++++++++++++++++++++
if($action=='modify'){

		echo"<form style='padding:0; margin:0;' name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" >";
		echo"<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\">";

 		if($_SESSION['searchSubscriptions'] == 'true' || isset($_GET['UWID'])){
			echo("<TR><TD valign=\"top\" align=\"center\">\n");

			echo("<TABLE width=\"100%\" border=\"1\" cellpadding=\"4\" cellspacing=\"0\">\n");
			echo("<TR class=\"blockHeader\"> <TD></TD> <TD>Underwriter</TD> <TD>System ID</TD> </TR>\n");

			if(isset($_GET['UWID'])){//get UW's from drop down list
				$result = array();
				$sth = "SELECT * FROM $underwriter_Table WHERE ID = '".$_GET['UWID']."'";
				$result[] = $db->getAll($sth,DB_FETCHMODE_ASSOC);
				$_SESSION['searchSubscriptions'] = 'false';
				$_SESSION['updateArray'][] = $_GET['UWID'];
			}else{
				$result = array();
				for ($r = 0; $r < count($_SESSION['updateArray']); $r++) {
					$sth = "SELECT * FROM $underwriter_Table WHERE ID = '".$_SESSION['updateArray'][$r]."'";
					$result[] = $db->getAll($sth,DB_FETCHMODE_ASSOC);
				  }
			 }



			if (DB::isError($result)) {
			die ($result->getMessage());
			}
			$i = 0;
			$ii = 1;
			while($i < count($result)){
			$ID = $_SESSION['updateArray'][$i];
			$UW_Name = stripslashes($result[$i][0]['name']);
			$Abbreviation = $result[$i][0]['abbreviation'];
			if($i & 1){
			echo("<TR class=\"odd\"> <TD class=\"numbers\"><INPUT name=\"originalAbbreviation$i\" type=\"hidden\" value=\"$Abbreviation\"><INPUT name=\"ID$i\" type=\"hidden\" value=\"$ID\">$ii)</TD> <TD><INPUT name=\"name$i\" type=\"text\" value=\"$UW_Name\" size=\"40\"></TD> <TD><INPUT name=\"abbreviation$i\" type=\"text\" value=\"$Abbreviation\" size=\"30\"></TD> </TR>\n");
			}else{
			echo("<TR class=\"even\"> <TD class=\"numbers\"><INPUT name=\"originalAbbreviation$i\" type=\"hidden\" value=\"$Abbreviation\"><INPUT name=\"ID$i\" type=\"hidden\" value=\"$ID\">$ii)</TD> <TD><INPUT name=\"name$i\" type=\"text\" value=\"$UW_Name\" size=\"40\"></TD> <TD><INPUT name=\"abbreviation$i\" type=\"text\" value=\"$Abbreviation\" size=\"30\"></TD> </TR>\n");
			}
			++$i;
			++$ii;
			}

				echo("<INPUT name=\"highnumber\" type=\"hidden\" value=\"$i\"></TABLE>\n");
				echo("</TD></TR>\n");

				echo" <script language=\"JavaScript\" type=\"text/javascript\">
				<!--
				function alertHistorical(){
					if(document.form.historical.checked == true){
					alert(\"WARNING! This will alter all occurences in the Grid!\");
				}
				}//end function
				//-->
				</script>";

			echo("<TR><TD bgcolor=\"#666666\"><TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><TR><TD width=\"35%\"  class=\"footerText\">Update historical grid entries:<input name=\"historical\" type=\"checkbox\" value=\"true\" onClick=\"alertHistorical()\"></TD><TD align=\"center\"><INPUT name=\"action\" type=\"hidden\" value=\"modify\"><INPUT name=\"Submit\" type=\"submit\" class=\"inputButton\"  value=\"Submit\"> &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"reset\" class=\"inputButton\" value=\"Reset\"></TD><TD width=\"35%\">&nbsp;</TD></TR></TABLE>   </TD></TR>\n");

		}else if($_SESSION['searchSubscriptions'] == 'false'){//DISPLAY CONFIRMATION OF UNDERWRITERS THAT HAVE BEEN UPDATED
						echo("<TR><TD valign=\"top\" align=\"center\">");

						echo("<TABLE width=\"100%\" border=\"1\" cellpadding=\"4\" cellspacing=\"0\">\n");
						echo("<TR class=\"blockHeader\"> <TD></TD> <TD>Underwriter</TD> <TD>System ID</TD> </TR>\n");

						$result = array();
						for ($r = 0; $r < count($_SESSION['updateArray']); $r++) {
							$sth = "SELECT * FROM $underwriter_Table WHERE ID = '".$_SESSION['updateArray'][$r]."'";
							$result[] = $db->getAll($sth,DB_FETCHMODE_ASSOC);
						  }
						if (DB::isError($result)) {
						die ($result->getMessage());
						}


						$i = 0;
						$ii = 1;
						while($i < count($_SESSION['updateArray'])){
						$ID = $_SESSION['updateArray'][$i];
						$UW_Name = stripslashes($result[$i][0]['name']);
						$Abbreviation = stripslashes($result[$i][0]['abbreviation']);
						if($i & 1){
						echo("<TR class=\"odd\"> <TD class=\"numbers\">$ii)</TD> <TD>$UW_Name</TD> <TD>$Abbreviation</TD> </TR>\n");
						}else{
						echo("<TR class=\"even\"> <TD class=\"numbers\">$ii)</TD> <TD>$UW_Name</TD> <TD>$Abbreviation</TD> </TR>\n");
						}
						++$i;
						++$ii;
						}


						echo("</TABLE>\n");
						echo("</TD></TR>\n");
						echo("<TR><TD valign=\"middle\" align=\"center\" bgcolor=\"#666666\">&nbsp;</TD></TR>\n");

		}else{//SHOW FORM FOR CHOOSING A SINGLE UW TO UPDATE
				//Javascript for Drop Down Jump List
					echo("<script language=\"JavaScript\" type=\"text/javascript\">
					function launch() {
						document.form.action= 'index.php?ID=0&subMenu=0&action=modify&UWID=' + document.form.name.value ;
						document.form.submit();
					}
					</script> ");

					echo("<INPUT name=\"action\" type=\"hidden\" value=\"search\"><INPUT name=\"singleSearch\" type=\"hidden\" value=\"true\"><TR><TD valign=\"top\" align=\"center\">\n");

					echo("<select name=\"name\" size=\"1\" onChange=\"launch()\"><option value=\"not_selected\" selected>Choose an underwriter to modify:</option>\n");


					$Query = "SELECT * FROM $underwriter_Table ORDER BY name asc";
					$result = $db->getAll($Query, DB_FETCHMODE_ASSOC);
					if (DB::isError($result)) {
					die ($result->getMessage());
					}

					for ($i = 0; $i < count($result); $i++) {
					$ID = $result[$i]['ID'];
					$name = stripslashes($result[$i]['name']);
					$value = $result[$i]['name'];
					echo("<option value=\"$ID\">$name</option>\n");
					}

					echo("</select></TD></TR>\n");
					echo("<TR><TD valign=\"middle\" align=\"center\" bgcolor=\"#666666\">&nbsp;</TD></TR>\n");
	}


		unset($_SESSION['updateArray']); //	empty update array
		unset($_SESSION['searchSubscriptions']);
		echo("</TABLE></FORM>");
}
		//+++++++++++++++++++++++
		//END CODE FOR Modifying UW's
		//+++++++++++++++++++++++



		//+++++++++++++++++++++++
		//BEGIN CODE FOR SEARCHING UW's
		//+++++++++++++++++++++++
if($action=='search'){


		//javascript to submit form on pressing enter
		echo"<script language=\"JavaScript\">
		<!--
		function submitForm(event,formName){
			if(event.keyCode==13 || (event && event.which == 13)){
				formCheck();
			}
		}
		//-->
		</script> ";

		echo"<form style='padding:0; margin:0;' name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" onKeyPress=\"submitForm(event,'form');\">";
		echo"<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\">";


			echo("<script language=\"javascript\" TYPE=\"text/javascript\">

			function formCheck(){

		if(document.form.name.value==\"\"){
		  document.form.name.focus();
		  alert (\"Please enter a search string!\");
		}else{
		  document.form.submit();
		}
			}
			</script>");

		echo("<TR><TD valign=\"top\" align=\"center\">");


echo"<!--BEGIN Row for Searching underwriters-->
<TR><TD>

  <table width=\"100%\"  border=\"0\" cellpadding=\"4\"><TR><TD>
  <table border=\"1\" width=\"100%\"  cellpadding=\"0\" cellspacing=\"0\"><TR><TD>

  	<table border=\"0\" width=\"100%\"  cellpadding=\"0\" cellspacing=\"0\">
	    <form action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" name=\"PrintOptions\">

		<TR>
			<TD class=\"blockHeader\">
			Search the Database for an Underwriter:
			</TD>
		</TR>

		<TR>
			<TD class=\"blockDescription\">
			Enter the name or part of the name to search for.
			</TD>
		</TR>

		<TR>
			<TD>
							<table border=\"0\" width=\"100%\"  cellpadding=\"4\" cellspacing=\"0\">
				<TR class=\"formElementText\" bgcolor=\"FFFFFF\">
					<TD>";



							echo "Name to Search: <INPUT name=\"name\" type=\"text\" size=\"30\">";


					echo"</TD><TD>";

							echo "Field to Search: <select name=\"searchfield\" size=\"1\" ><option value=\"name\" selected>Underwriter Name</option><option value=\"abbreviation\">System ID</option></select>";

					echo"</TD>
				</TR>
	</TABLE>
  			</TD>
		</TR>

		<!--SUBMIT BUTTON-->
  		<TR>
			<TD bgcolor=\"#CCCCCC\" align=\"center\" style=\"padding-top:5px; padding-bottom:5px; \">
            <INPUT name=\"action\" type=\"hidden\" value=\"search\"><INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" onClick=\"formCheck()\"> &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"reset\" class=\"inputButton\" value=\"Reset\">			</TD>
		</TR>
		<!--END SUBMIT BUTTON-->
		  </FORM>

  </TABLE>
  </TD></TR></TABLE>
  </TD></TR></TABLE>

  </TD></TR>
  <!--END Row for Searching new underwriters-->";

		echo("</TABLE></FORM>");
}
		//+++++++++++++++++++++++
		//END CODE FOR SEARCHING UW's
		//+++++++++++++++++++++++






}
//==========================================================================================
//END CODE FOR MANAGE UNDERWRITERS==========================================================
//==========================================================================================




//=========================================================================================
//BEGIN CODE FOR MANAGE AIR TIMES==========================================================
//=========================================================================================

if($subMenu == '1'){


$tabWidths = array();
  $tabWidths[0]['left'] = '0';
  $tabWidths[0]['text'] = 'List Air Times';
  $tabWidths[0]['action'] = 'list';

  $tabWidths[1]['left'] = '-24';
  $tabWidths[1]['text'] = 'Enter New Air Time';
  $tabWidths[1]['action'] = 'enter';



  //ADMIN NAVIGATION  - links get their styles from CSS: #admintopnav #a3
echo"<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
	<TR>
		<TD valign=\"bottom\"><ul id=\"admintopnav\">";

		for ($i = 0; $i < count($tabWidths); $i++) {
			if($action == $tabWidths[$i]['action']){
				echo "<li ><DIV style=\"left:" .$tabWidths[$i]['left'].";\" class=\"here\">" .$tabWidths[$i]['text']. "</DIV></li>";
			}else{
				echo"<li ><a id=\"a".($i+3)."\" href=\"index.php?ID=0&subMenu=1&action=".$tabWidths[$i]['action']."\" >" .$tabWidths[$i]['text']. "</a></li>";
			}
		}

			echo"</ul>
		</TD>
	</TR>
	<TR><TD><DIV class=\"adminsubnav3\"></DIV></TD></TR>
	</TABLE>";
 //END ADMIN NAVIGATION




//#####################################################
//BEGIN UPDATE AIR TIMES SECTION#######################
//#####################################################
if ($action == 'update' || $action == 'enter'){
		//Start "Manage Airtimes Drop Down Jump List
		echo("<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\"><FORM name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\"");

echo("<TR><TD><TABLE width=\"100%\" border=\"1\" cellpadding=\"4\" cellspacing=\"0\">\n");
echo("<TR class=\"blockHeader\"> <TD></TD>  <TD width=\"53\">Hour:</TD> <TD width=\"50\" >Min:</TD> <TD>Sec:</TD><TD>AM/PM</TD> <TD>Days of Week:</TD></TR>\n");

if(isset($_GET['fromPlannerID'])){
	$_SESSION['updateAirTimeArray'][0] = $_GET['fromPlannerID'];
	echo"<input name=\"fromPlanner\" type=\"hidden\" value=\"true\">\n";
}else if($action == 'enter'){
	$_SESSION['updateAirTimeArray'][0] = "";

}


		$result = array();
		for ($r = 0; $r < count($_SESSION['updateAirTimeArray']); $r++) {
			$sth = "SELECT * FROM $airtimes_Table WHERE ID = '".$_SESSION['updateAirTimeArray'][$r]."'";
			$result[] = $db->getAll($sth,DB_FETCHMODE_ASSOC);
		  }
		if (DB::isError($result)) {
		die ($result->getMessage());
		}

$w = 0;
$y = 1;
while($w < count($_SESSION['updateAirTimeArray'])){
	$myID = $result[$w][0][ID];
    $hour = $result[$w][0][hour];
    $minute = $result[$w][0][minute];
	$seconds = $result[$w][0][seconds];
    $ampm = $result[$w][0][ampm];
    $mon = $result[$w][0][mon];
    $tue = $result[$w][0][tue];
    $wed = $result[$w][0][wed];
    $thu = $result[$w][0][thu];
    $fri = $result[$w][0][fri];
    $sat = $result[$w][0][sat];
    $sun = $result[$w][0][sun];

	if($w & 1){
	$class = "class=\"odd\"";
	}else{
	$class = "class=\"even\"";
	}

echo("<TR $class> <TD class = \"numbers\">$y)<INPUT name=\"ID$w\" type=\"hidden\" value=\"$myID\"></TD>\n");
echo("<TD>");
if($action == 'enter'){
	echo"<select name=\"hour\" size=\"1\">\n";
}else{
	echo"<select name=\"hour$w\" size=\"1\">\n";
}

echo "<option value=\"\"></option>\n";

$q = 1;
while($q < 13){
if($q < 10){
$z = "0" . $q;
if($z == $hour){
echo "<option selected value=\"$z\">$q</option>\n";
}else{
echo "<option value=\"$z\">$q</option>\n";
}
}else{
if($q == $hour){
echo "<option selected value=\"$q\">$q</option>\n";
}else{
echo "<option value=\"$q\">$q</option>\n";
}
}

++$q;
}

echo("</select></TD><TD>\n");
if($action == 'enter'){
	echo"<select name=\"minute\" size=\"1\">\n";
}else{
	echo"<select name=\"minute$w\" size=\"1\">\n";
}

echo "<option value=\"\"></option>\n";
			  $i=0;
			 while($i < 60){
			 if(strlen($i) == 1){
			 $newdigit = "0".$i;
			 }else{
 			 $newdigit = $i;
			 }
			 if($newdigit == $minute){
			 echo("<option selected value=\"$newdigit\">$newdigit</option>\n");
			 }else{
			 echo("<option value=\"$newdigit\">$newdigit</option>\n");
			 }

			 ++$i;
			 }echo("</select>\n");

echo("</TD>\n");

echo "<TD>\n";
if($action == 'enter'){
	echo"<select name=\"seconds\" size=\"1\">\n";
}else{
	echo"<select name=\"seconds$w\" size=\"1\">\n";
}


if($_GET['fromPlannerID']){
  echo "<option selected value=\"30\">30</option>\n";
}else if($seconds == '00'){
 echo "<option selected value=\"00\">00</option><option value=\"30\">30</option>\n";
 }else if($seconds == '30'){
  echo "<option  value=\"00\">00</option><option selected value=\"30\">30</option>\n";
 }else{
  echo "<option selected value=\"\"></option><option  value=\"00\">00</option><option  value=\"30\">30</option>\n";
 }

echo"</SELECT></TD>\n";


echo("<TD>");
if($action == 'enter'){
	echo("<select name=\"ampm\" size=\"1\">\n");
}else{
	echo("<select name=\"ampm$w\" size=\"1\">\n");
}

 if($ampm == 'AM'){
 echo "<option selected value=\"AM\">AM</option>
			<option value=\"PM\">PM</option>\n";
 }else if($ampm == 'PM'){
  echo "<option value=\"AM\">AM</option>
			<option selected  value=\"PM\">PM</option>\n";
 }else{
  echo "<option value=\"\"></option><option value=\"AM\">AM</option>
			<option value=\"PM\">PM</option>\n";
	 }


echo("</SELECT></TD><TD class=\"formElementText\">\n");
if($mon == 'true'){
echo "mon<INPUT name=\"";
	if($action == 'enter'){
		echo"mon";
	}else{
		echo"mon$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" checked> | ";
}else{
	echo "mon<INPUT name=\"";
	if($action == 'enter'){
		echo"mon";
	}else{
		echo"mon$w";
	}
	echo"\" type=\"checkbox\" value=\"true\"> | ";
}



if($tue == 'true'){
echo "tue<INPUT name=\"";
	if($action == 'enter'){
		echo"tue";
	}else{
		echo"tue$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" checked> | ";
}else{
echo "tue<INPUT name=\"";
	if($action == 'enter'){
		echo"tue";
	}else{
		echo"tue$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" > | ";
}


if($wed == 'true'){
echo "wed<INPUT name=\"";
	if($action == 'enter'){
		echo"wed";
	}else{
		echo"wed$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" checked> | ";
}else{
echo "wed<INPUT name=\"";
	if($action == 'enter'){
		echo"wed";
	}else{
		echo"wed$w";
	}
	echo"\" type=\"checkbox\" value=\"true\"> | ";
}


if($thu == 'true'){
echo "thu<INPUT name=\"";
	if($action == 'enter'){
		echo"thu";
	}else{
		echo"thu$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" checked> | ";
}else{
echo "thu<INPUT name=\"";
	if($action == 'enter'){
		echo"thu";
	}else{
		echo"thu$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" > | ";
}

if($fri == 'true'){
echo "fri<INPUT name=\"";
	if($action == 'enter'){
		echo"fri";
	}else{
		echo"fri$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" checked> | ";
}else{
echo "fri<INPUT name=\"";
	if($action == 'enter'){
		echo"fri";
	}else{
		echo"fri$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" > | ";
}

if($sat == 'true'){
echo "sat<INPUT name=\"";
	if($action == 'enter'){
		echo"sat";
	}else{
		echo"sat$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" checked> | ";
}else{
echo "sat<INPUT name=\"";
	if($action == 'enter'){
		echo"sat";
	}else{
		echo"sat$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" > | ";
}

if($sun == 'true'){
echo "sun<INPUT name=\"";
	if($action == 'enter'){
		echo"sun";
	}else{
		echo"sun$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" checked> | ";
}else{
echo "sun<INPUT name=\"";
	if($action == 'enter'){
		echo"sun";
	}else{
		echo"sun$w";
	}
	echo"\" type=\"checkbox\" value=\"true\" > | ";
}

echo("</TD></TR>");



++$w;
++$y;
}

echo("</TD></TR></TABLE>\n\n");



echo "<script language=\"JavaScript\" type=\"text/javascript\">
<!--
function formCheck()
{
var submit = true; ";

if($action != 'enter'){

	for ($i = 0; $i < count($_SESSION['updateAirTimeArray']); $i++) {

	echo"
	if(document.form.hour$i.value == \"\" || document.form.minute$i.value == \"\" || document.form.seconds$i.value == \"\" || document.form.ampm$i.value == \"\"){
	alert (\"Please complete all fields for entry number " . ($i+1) . "!\")
	var submit = false;
	}

	if(document.form.mon$i.checked == false && document.form.tue$i.checked == false && document.form.wed$i.checked == false && document.form.thu$i.checked == false && document.form.fri$i.checked == false && document.form.sat$i.checked == false && document.form.sun$i.checked == false){
	alert (\"Please select days of week for entry number " . ($i+1) . "!\")
	var submit = false;
	}";


	}
}else{
	echo"
	if(document.form.hour.value == \"\" || document.form.minute.value == \"\" || document.form.seconds.value == \"\" || document.form.ampm.value == \"\"){
	alert (\"Please complete all fields!\")
	var submit = false;
	}

	if(document.form.mon.checked == false && document.form.tue.checked == false && document.form.wed.checked == false && document.form.thu.checked == false && document.form.fri.checked == false && document.form.sat.checked == false && document.form.sun.checked == false){
	alert (\"Please select days of week!\")
	var submit = false;
	}";
	}
echo"
if(submit != false){
document.form.submit();
}
}
//-->
</script> \n\n";





echo "<script language=\"JavaScript\" type=\"text/javascript\">
<!--
function deSelectAll(){

for (var q=0; q < document.form.elements.length; q++) {

				 // get each element of form form
				 var e = document.form.elements[q];

				 if( e.type.indexOf(\"checkbox\") == -1 ){
				// not a checkbox
				continue;
  				}else{
				e.checked = false;
				}



}

}
//-->
</script> ";

echo "<script language=\"JavaScript\" type=\"text/javascript\">
<!--
function selectWeekends(){

for (var q=0; q < document.form.elements.length; q++) {

				 // get each element of form form
				 var e = document.form.elements[q];

				 if( e.type.indexOf(\"checkbox\") == -1 ){
				// not a checkbox
				continue;
  				}

				if( e.name.indexOf(\"sat\") == 0 ){
				e.checked = true;
				}
				if( e.name.indexOf(\"sun\") == 0 ){
				e.checked = true;
				}



}

}
//-->
</script> ";

echo "<script language=\"JavaScript\" type=\"text/javascript\">
<!--
function selectWeekdays(){

for (var q=0; q < document.form.elements.length; q++) {

				 // get each element of form form
				 var e = document.form.elements[q];

				 if( e.type.indexOf(\"checkbox\") == -1 ){
				// not a checkbox
				continue;
  				}

				if( e.name.indexOf(\"mon\") == 0 ){
				e.checked = true;
				}
				if( e.name.indexOf(\"tue\") == 0 ){
				e.checked = true;
				}
				if( e.name.indexOf(\"wed\") == 0 ){
				e.checked = true;
				}
				if( e.name.indexOf(\"thu\") == 0 ){
				e.checked = true;
				}
				if( e.name.indexOf(\"fri\") == 0 ){
				e.checked = true;
				}



}
}
//-->
</script> ";

//BEGIN FOOTER
if($action == 'enter'){
   echo"<TR><TD valign=\"middle\" align=\"center\" bgcolor=\"#666666\"><INPUT name=\"highnumber\" type=\"hidden\" value=\"$w\"><TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><TR><TD width=\"33%\" align=\"center\" class=\"footerText\">Select All Weekdays:<INPUT name=\"weekdays\" type=\"radio\" value=\"true\" onClick=\"selectWeekdays()\"></TD> <TD width=\"33%\" align=\"center\">";
	echo"<INPUT name=\"action\" type=\"hidden\" value=\"enterairtime\">";
echo"<INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" onClick=\"formCheck()\"> &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"reset\" class=\"inputButton\" value=\"Reset\"> </TD> <TD width=\"33%\" align=\"center\" class=\"footerText\">Select All Weekends:<INPUT name=\"weekdays\" type=\"radio\" value=\"true\" onClick=\"selectWeekends()\"></TD></TR></TABLE></TD></TR>";
}else{
echo"<TR><TD valign=\"middle\" align=\"center\" bgcolor=\"#666666\"><INPUT name=\"highnumber\" type=\"hidden\" value=\"$w\"><TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><TR><TD width=\"33%\" align=\"center\" ></TD> <TD width=\"33%\" align=\"center\">";
	echo"<INPUT name=\"action\" type=\"hidden\" value=\"updateairtime\">";
echo"<INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" onClick=\"formCheck()\"> &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"reset\" class=\"inputButton\" value=\"Reset\"> </TD> <TD width=\"33%\" align=\"center\" style=\"color:#CCCCCC; font-size:smaller; font-weight:bold\"></TD></TR></TABLE></TD></TR>";
}

echo("</FORM></TABLE>");
//END FOOTER
unset($_SESSION['updateAirTimeArray']);
}


//#####################################################
//END UPDATE AIR TIMES SECTION#########################
//#####################################################








//#####################################################
//BEGIN LIST AIR TIMES SECTION##############
//#####################################################

if ($action == 'list' || !$action){

		//Javascript function to confirm delete
		echo("<script language=\"JavaScript\" type=\"text/javascript\">
		function confirmDelete() {
		var cMsg = \"\";
			for (var q=0; q < document.form.elements.length; q++) {

				 // get each element of form form
				 var e = document.form.elements[q];

				 if( e.name.indexOf(\"radioGroup\") == -1 ){
				// not a radioGroup element
				continue;
  				}

				 // determine whether delete radio button is checked
				if( e.value.indexOf(\"delete\") == -1 ){
				continue;
				}


				if(e.checked == true){
				var i = e.name.replace(/radioGroup/,\"\");
				var h = document.form.elements[\"deleteID\" + i];
				cMsg += \"\\t\" + h.value + \"\\n\";
  				}



			//ends Loop
			}

		if( cMsg != \"\" ){

		  // we have some deletes to confirm

		  cMsg = \"WARNING! All grid entries with these times will be removed as well.\\n\\n\" + cMsg + \"\\nContinue?\";

		  if(confirm(cMsg)){
		 document.form.submit();
		  }else{
		 return false;
		  }



		}else {
		document.form.submit();
		}


		//ends function
		}
		</script>");



		//javascript to submit form on pressing enter
		echo"<script language=\"JavaScript\">
		<!--
		function submitForm(event,formName){
			if(event.keyCode==13 || (event && event.which == 13)){
				confirmDelete();
			}
		}
		//-->
		</script> ";


		//Start "Manage UW Drop Down Jump List
		echo"<form style='padding:0; margin:0;' name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" onKeyPress=\"submitForm(event,'form');\">";
		echo"<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\">";

		//LIST OUT CURRENT AIR TIMES
		echo("<TR><TD valign=\"top\" align=\"center\">");
		$sql = "SELECT * FROM $airtimes_Table ORDER BY military";
		$result = $db->getAll($sql, DB_FETCHMODE_ASSOC);
     	if (DB::isError($result)) {
     	die ($result->getMessage());
     	}

		echo("<TABLE width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">");
		echo("<TR class=\"blockHeader\"> <TD width=\"15\">&nbsp;</TD>  <TD width=\"100\" >Air Time</TD> <TD>Days of Week</TD> <TD width=\"135\" >Action</TD> </TR>");

		$i = 0;
		$ii = 1;
		while ($i < count($result)) {
    	$ID = $result[$i][ID];
		$hour = $result[$i][hour];
		$minute = $result[$i][minute];
		$seconds = $result[$i][seconds];
		$ampm = strtolower($result[$i][ampm]);
		$mon = $result[$i][mon];
		$tue = $result[$i][tue];
		$wed = $result[$i][wed];
		$thu = $result[$i][thu];
		$fri = $result[$i][fri];
		$sat = $result[$i][sat];
		$sun = $result[$i][sun];

			$myDays = array();

			if($mon == 'true'){
			$myDays[] = mon;
			}
			if($tue == 'true'){
			$myDays[] = tue;
			}
			if($wed == 'true'){
			$myDays[] = wed;
			}
			if($thu == 'true'){
			$myDays[] = thu;
			}
			if($fri == 'true'){
			$myDays[] = fri;
			}
			if($sat == 'true'){
			$myDays[] = sat;
			}
			if($sun == 'true'){
			$myDays[] = sun;
			}

		echo("<input name=\"deleteID$i\" type=\"hidden\" value=\"$hour:$minute:$seconds $ampm\">\n");
		if($i & 1){
		echo("<TR onmouseover=\"setPointer(this, $i, 'over', '#CCCCCC', '#CCFFCC', '#FFCC99');\" onmouseout=\"setPointer(this, $i, 'out', '#CCCCCC', '#CCFFCC', '#FFCC99');\" onmousedown=\"setPointer(this, $i, 'click', '#CCCCCC', '#CCFFCC', '#FFCC99');\"> <TD BGCOLOR=\"#CCCCCC\" class=\"numbers\">$ii)</TD> <TD  BGCOLOR=\"#CCCCCC\" class=\"blockContent1\">$hour:$minute:$seconds $ampm</TD> <TD BGCOLOR=\"#CCCCCC\"  class=\"blockContent1\">");
		}else{
		echo("<TR onmouseover=\"setPointer(this, $i, 'over', '#FFFFFF', '#CCFFCC', '#FFCC99');\" onmouseout=\"setPointer(this, $i, 'out', '#FFFFFF', '#CCFFCC', '#FFCC99');\" onmousedown=\"setPointer(this, $i, 'click', '#FFFFFF', '#CCFFCC', '#FFCC99');\"> <TD BGCOLOR=\"#FFFFFF\" class=\"numbers\">$ii)</TD> <TD  BGCOLOR=\"#FFFFFF\"  class=\"blockContent1\">$hour:$minute:$seconds $ampm</TD> <TD BGCOLOR=\"#FFFFFF\"  class=\"blockContent1\">");
		}
			$z = 0;
			while($z < count($myDays)){
			if($z != (count($myDays) - 1)){
		    echo $myDays["$z"] . " $value | ";
			}else{
		    echo $myDays["$z"];
			}

			++$z;
			}

		if($i & 1){
		echo("</TD> <TD BGCOLOR=\"#CCCCCC\" class=\"formElementTextLeft\" nowrap>update<INPUT name=\"radioGroup$i\" type=\"radio\" value=\"update:$ID\" > | delete<INPUT name=\"radioGroup$i\" type=\"radio\" value=\"delete:$ID\"></TD></TR>\n\n");
		}else{
		echo("</TD> <TD BGCOLOR=\"#FFFFFF\" class=\"formElementTextLeft\" nowrap>update<INPUT name=\"radioGroup$i\" type=\"radio\" value=\"update:$ID\" > | delete<INPUT name=\"radioGroup$i\" type=\"radio\" value=\"delete:$ID\"></TD></TR>\n\n");
		}
		++$i;
		++$ii;
		}

		echo("<INPUT name=\"highnumber\" type=\"hidden\" value=\"$i\"></TABLE>");
		echo("</TD></TR>");

			echo("<TR><TD valign=\"middle\" align=\"center\" bgcolor=\"#666666\"><TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><TR><TD width=\"33%\" align=\"center\" style=\"color:#CCCCCC; font-size:smaller; font-weight:bold\"><!--Delete All:<INPUT name=\"updateAllYo\" type=\"radio\" onClick=\"updateAll()\"/>--></TD> <TD width=\"33%\" align=\"center\"><INPUT name=\"action\" type=\"hidden\" value=\"airtime\"><INPUT name=\"Submit\" type=\"button\" class=\"inputButton\"  value=\"Submit\" onClick=\"confirmDelete()\"> &nbsp; &nbsp; &nbsp; <INPUT name=\"Reset\" type=\"reset\" class=\"inputButton\" value=\"Reset\"> </TD> <TD width=\"33%\" align=\"center\" style=\"color:#CCCCCC; font-size:smaller; font-weight:bold\"><!--Update All:<INPUT name=\"deleteAllYo\" type=\"radio\" onClick=\"deleteAll()\"/>--></TD></TR></TABLE></TD></TR>");
			echo("</TABLE></FORM>");

}


//#####################################################
//END LIST AND UPDATE AIR TIMES SECTION################
//#####################################################



}
//==========================================================================================
//END CODE FOR MANAGE AIR TIMES=============================================================
//==========================================================================================





//==========================================================================================
//BEGIN CODE FOR GRID ITEMS=================================================================
//==========================================================================================

if($subMenu == '2'){


//++++++++++++++++++++++++++++++++++++++++++++++
//BEGIN FUNCTION TO DISPLAY FORM TO CHANGE WEEKS
//++++++++++++++++++++++++++++++++++++++++++++++
function JumpToWeek(){

echo "<FORM name=\"GO\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\"><TR><TD><TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\"width=\"100%\"><TR> <TD nowrap style=\"text-align:left; font-size:14px; font-weight:700; color:#000000; padding-left:5px; background-color:#BBBBBB; border-left: 5px solid #666666; border-bottom: 1px solid #000000;\">Week: " . date("D m/d/y",$_SESSION['timestamp']) . "&nbsp;-&nbsp;" . date("D m/d/y",($_SESSION['timestamp'] + 518400)) . "</TD> <TD class=\"adminsubnav\">";

						$monthsText = array("January","February","March","April","May","June","July","August","September","October","November","December");
						//Month Drop Down List
						echo("<select name=\"startMonth\" size=\"1\" id=\"setDateMonth\">\n");
						$i = 0;
						$q = 1;
						while($i < 12){
							if($q == $GLOBALS['MYtodaysMonth']){
							echo("<option value=\"$q\" selected>$monthsText[$i]</option>\n");
							}else{
							echo("<option value=\"$q\">$monthsText[$i]</option>\n");
							}
						++$i;
						++$q;
						}
						echo("</SELECT>\n\n");

						//Day Drop Down List
						echo("<select name=\"startDay\" size=\"1\" >\n");
						$i = 0;
						$q = 1;
						while($i < 31){
							if($q == $GLOBALS['MYtodaysDay']){
							echo("<option value=\"$q\" selected>$q</option>\n");
							}else{
							echo("<option value=\"$q\">$q</option>\n");
							}
						++$i;
						++$q;
						}
						echo("</SELECT>\n\n");


						//Year Drop Down List $yearToStartRecords
						echo("<select name=\"startYear\" size=\"1\" >\n");

						for ($i = $GLOBALS['yearToStartRecords']; $i < date("Y"); $i++) {

							if($i == $GLOBALS['MYtodaysYear']){
							echo("<option value=\"" . $i . "\" selected>" . $i . "</option>\n");
							}else{
							echo("<option value=\"" . $i . "\">" . $i . "</option>\n");
							}

						}


						$i = 0;
						while($i < 5){
							$futureYears = (date("Y") + $i);
							if($futureYears == $GLOBALS['MYtodaysYear']){
							echo("<option value=\"" . $GLOBALS['MYtodaysYear'] . "\" selected>" . $GLOBALS['MYtodaysYear'] . "</option>\n");
							}else{
							echo("<option value=\"$futureYears\">$futureYears</option>\n");
							}
						++$i;
						}
						echo("</SELECT>&nbsp; <INPUT name=\"Submit\" type=\"submit\" class=\"inputButton\"  value=\"Change Week\">\n");

			if($GLOBALS['action'] =='view'){
			echo"<INPUT name=\"action\" type=\"hidden\" value=\"viewGrid\">\n";
			}else if($GLOBALS['action'] =='planner' ||!$GLOBALS['action']){
			echo"<INPUT name=\"action\" type=\"hidden\" value=\"viewPlanner\">\n";
			}

echo"</TD></TR></TABLE></TD></TR></FORM>";
}

//++++++++++++++++++++++++++++++++++++++++++++++
//END FUNCTION TO DISPLAY FORM TO CHANGE WEEKS
//++++++++++++++++++++++++++++++++++++++++++++++






//++++++++++++++++++++++++++++++++++++++++++++++++++++
//BEGIN FUNCTION TO REMEBER AND ADD FIELDS ON ENTER FORM
//++++++++++++++++++++++++++++++++++++++++++++++++++++

function getEnterFunctions(){
			echo"<script language=\"JavaScript\" type=\"text/javascript\">
			<!--
			function rememberInfo(){
			document.form.action = 'formaction.php?rememberInfo=true';
			document.form.submit();
			}

			function addField(){
			document.form.action = 'formaction.php?generateMultiples=true';
			document.form.submit();
			}
			//-->
			</script> ";
echo "<FORM name=\"GO\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\"><TR><TD class=\"adminsubnav2\">";
echo"<INPUT name=\"Go\" type=\"button\" class=\"inputButton\"  value=\"Remember Info\" onClick = \"rememberInfo()\">&nbsp; &nbsp;<INPUT name=\"Go\" type=\"button\" class=\"inputButton\"  value=\"Add Field\" onClick = \"addField()\">";
echo"</TD></TR></FORM>";

}

//++++++++++++++++++++++++++++++++++++++++++++++++++++
//END FUNCTION TO REMEBER AND ADD FIELDS ON ENTER FORM
//++++++++++++++++++++++++++++++++++++++++++++++++++++





//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//BEGIN FUNCTION TO FIND THE NEAREST MONDAY TO SUBMITTED DATE
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	if(isset($_GET['TS'])){
		$_SESSION['timestamp'] = $_GET['TS'];
		}

						$todaysMonth = date("n");
						$todaysDay = date("j");
						$todaysYear = date("Y");
					if(!$_SESSION['timestamp']){
					//Function to find nearest Monday for current week
					function findNearestMonday($day,$startDay,$startMonth,$startYear){
					if($day == '0'){
					$monday = ($startDay - 6);
						if($monday < '0' && $startMonth != '1'){
						$lastMonthsmonday = (date("t",mktime(0,0,0,($startMonth - 1),$startDay,$startYear)) + $monday);
						$_SESSION['timestamp'] = mktime(0,0,0,($startMonth - 1),$lastMonthsmonday,$startYear);
						//January - go to December for nearest monday
						}else if($monday < '0' && $startMonth == '1'){
						$lastMonthsmonday = (date("t",mktime(0,0,0,12,$startDay,($startYear - 1))) + $monday);
						$_SESSION['timestamp'] = mktime(0,0,0,12,$lastMonthsmonday,($startYear - 1));
						}else{
						$_SESSION['timestamp'] = mktime(0,0,0,$startMonth,$monday,$startYear);
						}

					}else{
					$monday = ($startDay - $day) + 1;
					$_SESSION['timestamp'] = mktime(0,0,0,$startMonth,$monday,$startYear);
					}


				}
				findNearestMonday(date("w", mktime(0,0,0,$todaysMonth,$todaysDay,$todaysYear)),date("j"),date("n"),date("Y"));
				//end function

			}// end if(!$_SESSION['timestamp']){
						$MYtodaysMonth = date("n",$_SESSION['timestamp']);
						$MYtodaysDay = date("j",$_SESSION['timestamp']);
						$MYtodaysYear = date("Y",$_SESSION['timestamp']);



//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//END FUNCTION TO FIND THE NEAREST MONDAY TO SUBMITTED DATE
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//BEGIN FIGURE OUT CONTENT FOR HORIZONTAL MENU BAR
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$tabWidths = array();
  $tabWidths[0]['left'] = '0';
  $tabWidths[0]['text'] = 'View Weekly Planner';
  $tabWidths[0]['action'] = 'planner';

  $tabWidths[1]['left'] = '-25';
  $tabWidths[1]['text'] = 'View Live Grid';
  $tabWidths[1]['action'] = 'view';

  $tabWidths[2]['left'] = '-45';
  $tabWidths[2]['text'] = 'Enter New Grid Items';
  $tabWidths[2]['action'] = 'enter';



  //ADMIN NAVIGATION  - links get there styles from CSS: #admintopnav #a3
echo"<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
	<TR>
		<TD valign=\"bottom\"><ul id=\"admintopnav\">";

		for ($i = 0; $i < count($tabWidths); $i++) {
			if($action == $tabWidths[$i]['action']){
				echo "<li ><DIV style=\"left:" .$tabWidths[$i]['left'].";\" class=\"here\">" .$tabWidths[$i]['text']. "</DIV></li>";
			}else{
				echo"<li ><a id=\"a".($i+3)."\" href=\"index.php?ID=0&subMenu=2&action=".$tabWidths[$i]['action']."\" >" .$tabWidths[$i]['text']. "</a></li>";
			}
		}

			echo"</ul>
		</TD>
	</TR>";



	//DETERMINE SUBNAV CONTENT
 	if($action == 'planner' || $action == 'view'){
		JumpToWeek();
	}else if($action == 'enter'){
		getEnterFunctions();
	}else if($action == 'modifyGrid' || $action == 'verify'){
	echo "<TR><TD><DIV class=\"adminsubnav3\"></DIV></TD></TR>";//for Modify Grid Item from Live View
	}else{
	echo "<TR><TD><DIV class=\"adminsubnav\"></DIV></TD></TR>";
	}


	echo"</TABLE>";
 //END ADMIN NAVIGATION


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//END FIGURE OUT CONTENT FOR HORIZONTAL MENU BAR
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++






//############################################################################################################
//END OF HEADER FOR GRID SECTION------------------------------------------------------------------------------
//############################################################################################################




		//+++++++++++++++++++++++++++
		//BEGIN CODE FOR GRID PLANNER
		//+++++++++++++++++++++++++++
		if($action=='planner' || !$action){
		include ('includes/grid/WeeklyPlanner.php');
		}
		//+++++++++++++++++++++++++++
		//END CODE FOR GRID PLANNER
		//+++++++++++++++++++++++++++

//##############################################################################################

		//+++++++++++++++++++++++
		//BEGIN CODE FOR ENTERING NEW GRID ITEM
		//+++++++++++++++++++++++
		if($action=='enter'){
			echo"<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\">";
			//BEGINING OF FORM WHICH IS COMPLETED IN EACH ATTACHED INCLUDE BELOW
			echo "<FORM name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" >";
			include('includes/grid/EnterGridItem.php');
		}
		//+++++++++++++++++++++++
		//END CODE FOR ENTERING NEW GRID ITEM
		//+++++++++++++++++++++++

//##############################################################################################

		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//BEGIN CODE FOR VERIFYING GRID ENTRIES BEFORE SUBMITTING TO DATABASE
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//echo $action;

		if($action == 'verify'){
			echo"<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\">";
			//BEGINING OF FORM WHICH IS COMPLETED IN EACH ATTACHED INCLUDE BELOW
			echo "<FORM name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" >";			include('includes/grid/VerifyGridEntries.php');
		}
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//END CODE FOR VERIFYING GRID ENTRIES BEFORE SUBMITTING TO DATABSE
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


//#############################################################################################



		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//BEGIN CODE FOR UPDATING GRID ENTRIES
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		if($action=='modifyGrid'){
			echo"<TABLE width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"mainTableBGColor\">";
			//BEGINING OF FORM WHICH IS COMPLETED IN EACH ATTACHED INCLUDE BELOW
			echo "<FORM name=\"form\" action=\"formaction.php\" method=\"post\" enctype=\"multipart/form-data\" >";			include('includes/grid/ModifyGridEntries.php');
		}
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//END CODE FOR UPDATING GRID ENTRIES
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//##############################################################################################

		//+++++++++++++++++++++++
		//BEGIN CODE FOR VIEW GRID
		//+++++++++++++++++++++++
		if($action=='view'){
			include('includes/grid/ViewLiveGrid.php');
		}
		//+++++++++++++++++++++++
		//END CODE FOR VIEW GRID
		//+++++++++++++++++++++++
}
//==========================================================================================
//END CODE FOR GRID ENTRIES ITEM============================================================
//==========================================================================================

		$db->disconnect();//Close Connection to DB

		//clear session variables
		//$_SESSION = array();
		//session_unset();
		//session_destroy();
?>